package com.lhd.mpaas.demo.launcher;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.alipay.mobile.antui.basic.AUTitleBar;
import com.alipay.mobile.framework.LauncherApplicationAgent;
import com.alipay.mobile.nebula.provider.H5AppCenterPresetProvider;
import com.alipay.mobile.nebula.util.H5Utils;


/**
 * Created by mPaaS on 16/9/28.
 */
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.lhd.mpaas.demo.launcher.R.layout.main);

        AUTitleBar titleBar = findViewById(R.id.titlebar);
        titleBar.setTitleText("小程序");

        // 小程序基础库
        H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());

        // 离线资源包
        PresetAmrPipeline presetAmrPipeline = new PresetAmrPipeline();
        presetAmrPipeline.run();
        Log.d("==========>>>", "小程序前置条件");

        findViewById(R.id.btn_open_mini_app).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 启动小程序demo
//                Bundle bundle = new Bundle();
//                LauncherApplicationAgent.getInstance().getMicroApplicationContext()
//                        .startApp(null, "2019111412345678", bundle);

                String appId = "2019111412345678"; // "您的小程序的 appId";
                Bundle bundle = new Bundle();
                // 不设置就跳转发布小程序时的默认首页
//                bundle.putString(H5Param.PAGE, "跳转的页面路径");

                Log.d("==========>>>", "打开小程序");
                LauncherApplicationAgent.getInstance().getMicroApplicationContext().startApp(null, appId, bundle);
            }
        });
    }
}
